package com.stp.houbb;

import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 敏感词
 */
@Configuration
public class SensitiveWordBsConfig {

    @Autowired
    private CustomWordAllow customWordAllow;

    @Autowired
    private CustomWordDeny customWordDeny;

    /**
     * 初始化引导类
     *
     * 1	ignoreCase	忽略大小写
     * 2	ignoreWidth	忽略半角圆角
     * 3	ignoreNumStyle	忽略数字的写法
     * 4	ignoreChineseStyle	忽略中文的书写格式
     * 5	ignoreEnglishStyle	忽略英文的书写格式
     * 6	ignoreRepeat	忽略重复词
     * 7	enableNumCheck	是否启用数字检测。默认连续 8 位数字认为是敏感词
     * 8	enableEmailCheck	是有启用邮箱检测
     * 9	enableUrlCheck	是否启用链接检测
     *
     * @return 初始化引导类
     * @since 1.0.0
     */
    @Bean
    public SensitiveWordBs sensitiveWordBs() {
        // 可根据数据库数据判断 动态增加配置
        return SensitiveWordBs.newInstance()
                .wordDeny(WordDenys.chains(WordDenys.system(),customWordDeny)) // 设置黑名单
                .wordAllow(WordAllows.chains(WordAllows.system(), customWordAllow)) // 设置白名单
                .ignoreCase(true)
                .ignoreWidth(true)
                .ignoreNumStyle(true)
                .ignoreChineseStyle(true)
                .ignoreEnglishStyle(true)
                .ignoreRepeat(true)
                .enableEmailCheck(true)
                .enableUrlCheck(true)
                // 各种其他配置
                .init();
    }
}
